package cn.codeartist.springboot.component.dynamic.druid;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

/**
 * Druid 动态数据源
 *
 * @author 艾江南
 * @date 2019/4/2
 */
public class DynamicDataSource extends AbstractRoutingDataSource {

    final static private Logger logger = LoggerFactory.getLogger(DynamicDataSource.class);

    @Override
    protected Object determineCurrentLookupKey() {
        String dbType = DynamicDataSourceHolder.getDbType();
        logger.debug("select db source: [{}]", dbType);
        return dbType == null ? DynamicDataSourceHolder.DB_MASTER : dbType;
    }
}
